import 'package:efood_multivendor/controller/location_controller.dart';
import 'package:efood_multivendor/data/model/response/address_model.dart';
import 'package:efood_multivendor/helper/responsive_helper.dart';
import 'package:efood_multivendor/helper/size_config.dart';
import 'package:efood_multivendor/util/dimensions.dart';
import 'package:efood_multivendor/util/styles.dart';
import 'package:flutter/material.dart';
import 'package:flutter_feather_icons/flutter_feather_icons.dart';
import 'package:get/get.dart';

class AddressWidget extends StatelessWidget {
  final AddressModel address;
  final bool fromAddress;
  final bool fromCheckout;
  final Function()? onRemovePressed;
  final Function()? onEditPressed;
  final Function()? onTap;
  final bool fromSetting;
  AddressWidget(
      {required this.address,
      required this.fromAddress,
      this.onRemovePressed,
      this.onEditPressed,
      this.onTap,
      this.fromCheckout = false,
      this.fromSetting = false});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<LocationController>(builder: (locationController) {
      return Column(
        children: [
          Padding(
            padding: EdgeInsets.only(bottom: Dimensions.PADDING_SIZE_SMALL),
            child: InkWell(
              onTap: onTap,
              child: Container(
                padding: EdgeInsets.all(ResponsiveHelper.isDesktop(context)
                    ? Dimensions.PADDING_SIZE_DEFAULT
                    : Dimensions.PADDING_SIZE_SMALL / 2),
                decoration: BoxDecoration(
                  color: fromCheckout ? null : Theme.of(context).cardColor,
                  borderRadius: BorderRadius.circular(Dimensions.RADIUS_SMALL),
                  border: fromCheckout
                      ? Border.all(
                          color: Theme.of(context).disabledColor, width: 1)
                      : null,
                  boxShadow: fromCheckout || !fromSetting
                      ? null
                      : [
                          BoxShadow(
                              color: Colors.grey[Get.isDarkMode ? 800 : 200]!,
                              blurRadius: 5,
                              spreadRadius: 1)
                        ],
                ),
                child: Row(children: [
                  Icon(
                    address.addressType == 'home'
                        ? FeatherIcons.home
                        : address.addressType == 'office'
                            ? FeatherIcons.briefcase
                            : address.addressType == 'current_location'.tr
                                ? Icons.my_location_rounded
                                : FeatherIcons.flag,
                    size: ResponsiveHelper.isDesktop(context) ? 50 : 25,
                    color: Theme.of(context).colorScheme.secondary,
                  ),
                  SizedBox(width: Dimensions.PADDING_SIZE_SMALL),
                  Expanded(
                    child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(
                            address.addressType?.tr ?? '',
                            style: sfMedium.copyWith(
                                fontSize: Dimensions.fontSizeSmall * 0.35.w,
                                fontWeight: FontWeight.bold),
                          ),
                          SizedBox(
                              height: Dimensions.PADDING_SIZE_EXTRA_SMALL / 2),
                          Text(
                            address.address ?? '',
                            style: sfRegular.copyWith(
                                fontSize: Dimensions.fontSizeExtraSmall * 0.3.w,
                                color: Theme.of(context).disabledColor),
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                          ),
                        ]),
                  ),
                  fromAddress
                      ? IconButton(
                          icon: Icon(FeatherIcons.trash,
                              color: Color.fromARGB(255, 0, 0, 0),
                              size: ResponsiveHelper.isDesktop(context)
                                  ? 35
                                  : 25),
                          onPressed: onRemovePressed,
                        )
                      : SizedBox(),
                ]),
              ),
            ),
          ),
          fromSetting
              ? SizedBox()
              : Divider(
                  height: 1,
                  color: Theme.of(context).disabledColor,
                  indent: 30,
                  endIndent: 30,
                ),
        ],
      );
    });
  }
}
